#include "EnemyTypeA.h"
#include <time.h>
EnemyTypeA::EnemyTypeA() 
	: mActive(false)
	,mType("A")
{
}

EnemyTypeA::~EnemyTypeA()
{

}

void EnemyTypeA::Load()
{
	mSprite.Load("EnemyTypeA.png");
}

void EnemyTypeA::Unload()
{
	mSprite.Unload();
}

void EnemyTypeA::Update(float deltaTime,Map& mmap)
{
	if (mActive)
	{
		mPosition +=mVelocity * deltaTime;
		delay-=deltaTime;
		if ( delay <= 0.0f)
		{
			SVector2 temporary=mVelocity;

			temporary.x=-mVelocity.x;
			mVelocity=temporary;


			srand(time(NULL));
			mRandomSpawnCount = 1+rand() %3;
			const int kWinWidth = IniFile_GetInt("WinWidth", 800);
			switch(mRandomSpawnCount)
			{
			case 1:
			{

			delay=RandomFloat(0.8,2.5f);
			break;

			}

			case 2:
			{

			delay=RandomFloat(2.0,3.5f);
			break;

			}


			case 3:
			{
			delay=RandomFloat(1.3,3.9f);
			break;
			}
		}
		}
		
		mPosition += mVelocity * deltaTime;
		const int kWinWidth = IniFile_GetInt("WinWidth",800);//the number is just incase the program cant get the int. Number is basically a default
		const int kWinHeight = IniFile_GetInt("WinHeight",600);
		const int kThreshold = mSprite.GetWidth();
		/*if(mPosition.x < -kThreshold || mPosition.x > kWinWidth+kThreshold || mPosition.y < -kThreshold || mPosition.y > kWinHeight + kThreshold)
		{
			Kill();
		}*/

		if(mPosition.x <= 0.0f - (mSprite.GetWidth() * 0.5f))
		{
			mPosition.x = mmap.GetWidth() - 0.1f;
		}
		else if(mPosition.x >= mmap.GetWidth() + (mSprite.GetWidth() * 0.5f))
		{
			mPosition.x = mSprite.GetWidth()/2;
		}

		
		if(mPosition.y <= 0.0f - (mSprite.GetHeight() * 0.5f))
		{
			mPosition.y = mmap.GetHeight() - 0.5f;
		}
		else if(mPosition.y >= mmap.GetHeight() + (mSprite.GetHeight() * 0.5f))
		{
			mPosition.y = 0.0f;
		}
	}

}

void EnemyTypeA::Render(const SVector2 viewOffset)
{
	if (mActive)
	{ 
		
		const int width = mSprite.GetWidth();
		const int height = mSprite.GetHeight();
		SVector2 offset(width * 0.5f,height * 0.5f);
		SVector2 renderPosition = mPosition - offset -viewOffset;
		mSprite.SetPosition(renderPosition);
		mSprite.Render();

	}
	
}

void EnemyTypeA::Spawn(const SVector2& pos)
{
	mPosition = pos;
	mVelocity = SVector2(200.0f,200.f);
	mActive = true;
}

void EnemyTypeA::Kill()
{
	
	mActive = false;
	
}

string EnemyTypeA::GetEnemyType()
{
	return mType;

}

SVector2 EnemyTypeA:: GetPosition()
{
	return mPosition;
}